const Layout = () => import("@/layout/index");
import Vue from "vue";
import Router from "vue-router";
import {getUrl} from '@/utils'

import store from "@/store";

const baseUrl = getUrl();

Vue.use(Router);

const staticRoutes = [
  {
    path: "/",
    component: Layout,
    redirect: "/home",
    children: [
      {
        path: "/home",
        name: "",
        component: () => import("@/views/index"),
        meta: {
          // 是否显示导航栏
          isNavbar: false,
        },
      },
      {
        path: "/apply",
        name: "Apply",
        meta: {
          title: "申请补贴",
        },
        component: () => import("@/views/apply.vue"),
      },
      {
        path: "/query",
        name: "Query",
        meta: {
          title: "申请列表",
        },
        component: () => import("@/views/query.vue"),
      },
      {
        path: "/progress",
        name: "Progress",
        meta: {
          title: "进度查看",
        },
        component: () => import("@/views/progress.vue"),
      },
      {
        path: "/403",
        name: "403",
        meta: {
          isNavbar: false,
        },
        component: () => import("@/views/403.vue"),
      },
    ],
  },
];
const createRouter = () =>
  new Router({
    mode: "hash", // require service support
    scrollBehavior: () => ({ y: 0 }),
    base: baseUrl,
    routes: staticRoutes,
  });

const router = createRouter();

router.beforeEach((to, from, next) => {
  store.commit('SET_TITLE', to.meta.title)
  store.commit('SET_IS_NAVBAR', to.meta.isNavbar == undefined ? true : false)
  next();
});

export default router;
